package com.example.dee.filter;

import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName HtmlFilter
 * @Description TODO
 * @Author DicksonDee
 * @Date 2022/4/18 0018 16:48
 * @Version V1.0
 **/

@Order(10)
@WebFilter(filterName = "htmlFilter",urlPatterns = "*.html")
public class HtmlFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig)  {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("不能直接访问html页面");
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.sendRedirect("/");
        return;
    }

    @Override
    public void destroy() {

    }
}
